/**
 * 原来有数据，现在附加一些数据
 */
function appendData(oldData, newData) {
    if (!newData.results)return;
    if (!oldData) oldData={};
    initOldData(oldData);
    var oldNodes = oldData.results[0].data[0].graph.nodes;
    var oldRelations = oldData.results[0].data[0].graph.relationships;
    var oldNodesDir = {};
    for (var i = 0; i < oldNodes.length; i++) {
        oldNodesDir[oldNodes[i].id] = oldNodes[i];
    }
    var oldRelationDir = {};
    for (var i = 0; i < oldRelations.length; i++) {
        var key = oldRelations[i].startNode + "-" + oldRelations[i].endNode;
        oldRelationDir[key] = oldRelations[i];
    }

    var newNodes = newData.results[0].data[0].graph.nodes;
    var newRelations = newData.results[0].data[0].graph.relationships;

    for (var i = newNodes.length - 1; i > -1; i--) {
        //已经存在
        if (oldNodesDir[newNodes[i].id]) {
            newNodes.splice(i, 1);
            continue;
        }
        oldNodesDir[newNodes[i].id] = newNodes[i];
        oldNodes.push(newNodes[i]);
    }

    for (var i = newRelations.length - 1; i > -1; i--) {
        var key = newRelations[i].startNode + "-" + newRelations[i].endNode;
        if (oldRelationDir[key]) {
            newRelations.splice(i, 1);
            continue;
        }
        oldRelationDir[key] = newRelations[i];
        oldRelations.push(newRelations[i]);
    }
    return oldData;
}
function initOldData(oldData){
    oldData.results = oldData.results||[{}];
    oldData.results[0].data = oldData.results[0].data||[{}];
    oldData.results[0].data[0].graph = oldData.results[0].data[0].graph||{};
    oldData.results[0].data[0].graph.nodes = oldData.results[0].data[0].graph.nodes||[];
    oldData.results[0].data[0].graph.relationships = oldData.results[0].data[0].graph.relationships || [];
}